package com.tiger.web.controller.system;
import com.tiger.common.annotation.Log;
import com.tiger.common.core.controller.BaseController;
import com.tiger.common.core.domain.AjaxResult;
import com.tiger.common.core.page.TableDataInfo;
import com.tiger.common.enums.BusinessType;
import com.tiger.common.core.domain.entity.Department;
import com.tiger.system.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 部门Controller
 *
 * @author standard
 * @date 2022-10-31
 */
@Api(tags = "部门")
@RestController
@RequestMapping("/system/department")
public class DepartmentController extends BaseController {
    @Autowired
    private IDepartmentService departmentService;

    /**
     * 查询部门列表
     */
    @ApiOperation(value = "查询部门列表")
    //@PreAuthorize("@ss.hasPermi('system:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(Department department) {
        startPage();
        List<Department> list = departmentService.selectDepartmentList(department);
        return getDataTable(list);
    }


    /**
     * 获取部门详细信息
     */
    @ApiOperation(value = "获取部门列详细信息")
    //@PreAuthorize("@ss.hasPermi('system:department:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(departmentService.selectDepartmentById(id));
    }

    /**
     * 新增部门
     */
    @ApiOperation(value = "新增部门")
    //@PreAuthorize("@ss.hasPermi('system:department:add')")
    @Log(title = "部门", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Department department) {
        return toAjax(departmentService.insertDepartment(department));
    }

    /**
     * 修改部门
     */
    @ApiOperation(value = "修改部门")
    //@PreAuthorize("@ss.hasPermi('system:department:edit')")
    @Log(title = "部门", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Department department) {
        return toAjax(departmentService.updateDepartment(department));
    }

    /**
     * 删除部门
     */
    @ApiOperation(value = "删除部门")
    //@PreAuthorize("@ss.hasPermi('system:department:remove')")
    @Log(title = "部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(departmentService.deleteDepartmentById(id));
    }
}
